package com.avantis.common.entity;

import com.avantis.common.entity.base.BaseEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;


import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;


/**
 * @Author: tracywang
 * @Date: 2018/12/25
 * @Descrption:
 */
@Entity
@Table(name = "k_level")
@Data
public class Level extends BaseEntity implements Serializable {

    /**
     * 等级类别 0:客户等级;1:供应商等级
     */
    @ApiModelProperty("等级类型")
    @NotNull(message = "等级类型必填项！")
    @Column
    private Integer levelType;


    /**
     * 等级 0:普通;1:一级;2:二级,3:三级
     * 默认为普通
     */
    @ApiModelProperty("等级划分")
    @NotNull(message = "等级划分必填项！")
    @Column()
    private Integer level;

    /**
     * 零售价/批发价、默认等级价、等级价一、等级价二、等级价三
     */
    @ApiModelProperty("等级描述")
    @NotBlank(message = "等级描述必填项！")
    @Column()
    private String priceLevel;

    /**
     * 普通100%(不可修改)、90%、80%、70%
     */
    @ApiModelProperty("折扣率")
    @NotNull(message = "折扣率必填项！")
    @Column(scale = 2)
    private Double discount=1.00;

    @JsonIgnore
    @JoinTable(name = "k_level_customer",
            joinColumns = {@JoinColumn(name = "level_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "customer_id", referencedColumnName = "id")})
    @OneToMany(cascade = CascadeType.ALL)
    private Set<Customer> customers = new HashSet<>();

    @JsonIgnore
    @JoinTable(name = "k_level_supplier",
            joinColumns = {@JoinColumn(name = "level_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "supplier_id", referencedColumnName = "id")})
    @OneToMany(cascade = CascadeType.ALL)
    private Set<Supplier> suppliers = new HashSet<>();
}
